package com.example.faas.model;

import java.io.Serializable;

public class Response implements Serializable {

    public Response() {
    }

    public Response(boolean success) {
        this.success = success;
    }

    public Response(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }

    public Response(boolean success, Object data) {
        this.success = success;
        this.data = data;
    }

    public Response(boolean success, Object data, String msg) {
        this.success = success;
        this.data = data;
        this.msg = msg;
    }

    public static Response success(Object data, String msg) {
        return new Response(true, data, msg);
    }

    public static Response success(Object data) {
        return new Response(true, data);
    }

    public static Response success() {
        return new Response(true);
    }

    public static Response fail(Object data, String msg) {
        return new Response(false, data, msg);
    }

    public static Response fail(String msg) {
        return new Response(false, msg);
    }

    public static Response fail() {
        return new Response(false);
    }

    private boolean success;

    private String msg;

    private Object data;

    public boolean isSuccess() {
        return success;
    }

    public boolean isFail() {
        return !success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public <T> T parse() {
        return (T) data;
    }

    @Override
    public String toString() {
        return "Response{" +
                "success=" + success +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
